import Mock from 'mockjs'

const rowsListItems = Mock.mock({
  'items|200': [{
    idCode: '@id',
    userKey: '@integer(3000, 5000)',
    userName: '@cname',
    cTime: '@datetime',
    eMail: '@email'
  }]
})

const columns = [{
  key: 'idCode',
  title: '身份证',
  width: '300px'
},
{
  key: 'userKey',
  title: '登录名',
  width: '100px'
},
{
  key: 'eMail',
  title: '邮箱',
  width: '300px'
},
{
  key: 'cTime',
  title: '创建日期',
  width: '200px'
}]
const rules = {
  idCode: [
    { required: true, message: '身份证是必须的', trigger: 'blur' },
    { min: 15, max: 18, message: '身份证15-18位之间', trigger: 'blur' }
  ],
  userKey: [
    { required: true, message: '登录名是必须的', trigger: 'blur' }
  ]
}
const buttons = [{
  key: 'vb-add',
  title: '添加',
  status: 'success',
  icon: 'el-icon-plus'
},
{
  key: 'vb_user1',
  title: '自定义',
  type: '',
  icon: 'el-icon-printer'
}]
const rowButtons = [{
  key: 'vrb-edit',
  title: '',
  status: 'primary',
  icon: 'el-icon-edit'
},
{
  key: 'vrb-view',
  title: '',
  status: 'success',
  icon: 'el-icon-search'
},
{
  key: 'vrb-delete',
  title: '',
  status: 'danger',
  icon: 'el-icon-delete'
},
{
  key: 'vrb_user1',
  title: '自定义',
  status: 'primary',
  icon: 'el-icon-lock'
}]
const viewFormButtons = [{
  key: 'vfb-add',
  title: '添加',
  status: 'success',
  icon: 'el-icon-plus'
},
{
  key: 'vfb-delete',
  title: '删除',
  status: 'danger',
  icon: 'el-icon-delete'
},
{
  key: 'vfb-save',
  title: '保存',
  status: 'success',
  icon: 'el-icon-save'
},
{
  key: 'vfb-cancel',
  title: '取消',
  status: 'primary',
  icon: 'el-icon-delete'
}]
const viewFormFlowButtons = [{
  key: 'vffb-commit',
  title: '提交',
  status: 'primary',
  'node-filter': [1],
  icon: 'el-icon-save'
}]
const userQuery = [{
  key: 'idCode',
  title: '身份证'
},
{
  key: 'userKey',
  title: '登录名'
},
{
  key: 'eMail',
  title: '邮箱'
},
{
  key: 'cTime',
  title: '创建日期',
  type: 'dateArea'
}]
const viewFormDictionaries = {
  userType: [
    {
      value: 'normal',
      label: '普通用户'
    },
    {
      value: 'super',
      label: '超级用户'
    }
  ]
}
const flowNodes = [
  {
    label: '待审核',
    value: 1
  },
  {
    label: '已审核',
    value: -1
  }
]
const settings = {
  viewKey: 'users',
  checkbox: true,
  primaryKey: 'idCode',
  buttons,
  rowButtons,
  userQuery,
  flowNodes,
  rules,
  viewFormButtons,
  viewFormFlowButtons,
  viewFormDictionaries
}
function fetchUser(config) {
  return Mock.mock({
    idCode: config.query.idCode,
    userKey: '@integer(3000, 5000)',
    userName: '@cname',
    cTime: '@datetime',
    eMail: '@email',
    userType: 'super'
  })
}
export default [
  {
    url: '/uvUser/dvStructure',
    type: 'get',
    response: (config) => {
      return {
        code: 0,
        message: 'get user list structure OK!',
        data: {
          columns,
          settings
        }
      }
    }
  },
  {
    url: '/uvUser/dvData',
    type: 'get',
    response: () => {
      return {
        code: 0,
        message: 'get user list OK!',
        data: {
          total: 205,
          rows: rowsListItems.items
        }
      }
    }
  },
  {
    url: '/uvUser/getByPK',
    type: 'get',
    response: (config) => {
      return {
        code: 0,
        message: 'get user OK!',
        data: {
          row: fetchUser(config)
        }
      }
    }
  },
  {
    url: '/uvUser/delete',
    type: 'post',
    response: (config) => {
      return {
        code: 0,
        message: 'delete user OK!'
      }
    }
  },
  {
    url: '/uvUser/save',
    type: 'post',
    response: (config) => {
      return {
        code: 0,
        message: 'save user OK!'
      }
    }
  }
]
